package com.design.javaManage.utils;



//用于获取当前登录用户的基本信息


import com.design.javaManage.entity.SysUser;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtils {

    // 从Security主体信息获取用户信息

    public static SysUser getUser(){
        SysUser user = (SysUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        user.setPassword(null);
        user.setName(user.getUsername());
        return user;
    }

    // 在Security中获取用户名

    public static String getUsername(){
        return getUser().getUsername();
    }

    // 在Security中获取用户ID

    public static Long getUserId(){
        return getUser().getId();
    }
}
